package com.ruoyi.web.controller.mobile;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.mobile.domain.MedicalRecord;
import com.ruoyi.mobile.service.IMedicalRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 病历记录Controller
 * 
 * @author ruoyi
 * @date 2022-09-19
 */
@RestController
@RequestMapping("/mobile/medicalrecord")
public class MedicalRecordController extends BaseController
{
    @Autowired
    private IMedicalRecordService medicalRecordService;

    /**
     * 查询病历记录列表
     */
    @PreAuthorize("@ss.hasPermi('mobile:medicalrecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(MedicalRecord medicalRecord)
    {
        startPage();
        List<MedicalRecord> list = medicalRecordService.selectMedicalRecordList(medicalRecord);
        return getDataTable(list);
    }

    /**
     * 导出病历记录列表
     */
    @PreAuthorize("@ss.hasPermi('mobile:medicalrecord:export')")
    @Log(title = "病历记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MedicalRecord medicalRecord)
    {
        List<MedicalRecord> list = medicalRecordService.selectMedicalRecordList(medicalRecord);
        ExcelUtil<MedicalRecord> util = new ExcelUtil<MedicalRecord>(MedicalRecord.class);
        util.exportExcel(response, list, "病历记录数据");
    }

    /**
     * 获取病历记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('mobile:medicalrecord:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(medicalRecordService.selectMedicalRecordById(id));
    }

    /**
     * 新增病历记录
     */
    @PreAuthorize("@ss.hasPermi('mobile:medicalrecord:add')")
    @Log(title = "病历记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MedicalRecord medicalRecord)
    {
        return toAjax(medicalRecordService.insertMedicalRecord(medicalRecord));
    }

    /**
     * 修改病历记录
     */
    @PreAuthorize("@ss.hasPermi('mobile:medicalrecord:edit')")
    @Log(title = "病历记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MedicalRecord medicalRecord)
    {
        return toAjax(medicalRecordService.updateMedicalRecord(medicalRecord));
    }

    /**
     * 删除病历记录
     */
    @PreAuthorize("@ss.hasPermi('mobile:medicalrecord:remove')")
    @Log(title = "病历记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(medicalRecordService.deleteMedicalRecordByIds(ids));
    }
}
